﻿using System;
using DMS.BaseClass;
using DMS.Business.Modules.Organization;
using DMS.Business.Utility;

namespace DMS.Business.Modules.Configuation
{
    /// <summary>
    /// 配置项
    /// </summary>
    public class SysConfig
    {
        #region 成员数据
        private string _ID = string.Empty;
        private string _Name = string.Empty;
        private string _Value = string.Empty;
        private ParamTypes _Type = ParamTypes.System;

        private bool _IsDisplay = true;
        private bool _IsBuildIn = true;

        /// <summary>
        /// 标识
        /// </summary>
        public string ID
        {
            get
            {
                return this._ID;
            }
        }
        /// <summary>
        /// 显示标题
        /// </summary>
        public string Name
        {
            get
            {
                return this._Name;
            }
            internal set
            {
                this._Name = value;
            }
        }
        /// <summary>
        /// 值
        /// </summary>
        public string Value
        {
            get
            {
                return this._Value;
            }
            set
            {
                this._Value = value;
            }
        }
        /// <summary>
        /// 类型
        /// </summary>
        public ParamTypes Type
        {
            get
            {
                return this._Type;
            }
            internal set
            {
                this._Type = value;
            }
        }
        /// <summary>
        /// 是否内置
        /// </summary>
        public bool IsBuildIn
        {
            get
            {
                return this._IsBuildIn;
            }
            internal set
            {
                this._IsBuildIn = value;
            }
        }
        /// <summary>
        /// 是否显示
        /// </summary>
        public bool IsDisplay
        {
            get
            {
                return this._IsDisplay;
            }
            internal set
            {
                this._IsDisplay = value;
            }
        }
        #endregion

        #region 构造函数
        public SysConfig(string id)
        {
            this._ID = id;
        }
        #endregion

        #region 成员方法
        public void Save()
        {
            string oldConfigValue = string.Empty;
            SysConfig oldConfig = ConfigHelper.GetSysConfigByID(this.ID);
            if (oldConfig != null)
            {
                oldConfigValue = oldConfig.Value;
            }
            AuthenticationUser user = SystemContext.Current.LoginAuthUser;
            string msg = string.Format(@"用户“{0}({1})”于“{2}”修改系统配置：“{3}({4})”。<br />
                                         原配置值：“{5}”；<br />
                                         新配置值：“{6}”；"
                                        , user.Name
                                        , user.LoginID
                                        , DateTime.Now.ToString()
                                        , this.Name
                                        , this.ID
                                        , oldConfigValue
                                        , this.Value);
            LogHelper.LogAction("修改系统配置", msg);

            ConfigHelper.UpdateSysConfig(this);
        }
        #endregion
    }
}
